using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

//using DebugTerminal;

namespace Demo_SteeringBehaviour
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        SpriteFont font;

        #region PREV CODE_BASE
        //
        ////Agent001 player, enemy;
        ////Agent001 test;
        ////Random xPosSeed = new Random((int)DateTime.Now.Ticks);
        ////Random yPosSeed = new Random((int)DateTime.Now.Ticks);//DateTime.Now.Millisecond);
        //
        #endregion

        Rock rock; Paper paper; Scissor scissor;
        Controller crtl;
        int ctr = 1;

        //Constructor
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;

            IsMouseVisible = true;
        }

        
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            #region PREV CODE_BASE
            //
            ////player = new Agent001(Content.Load<Texture2D>("Rock_16x16"), Content.Load<Texture2D>("CollisionBoundary"));
            ////enemy = new Agent001(Content.Load<Texture2D>("Paper_16x16"), Content.Load<Texture2D>("CollisionBoundary"));
            ////test = new Agent001(Content.Load<Texture2D>("Rock_16x16"), Content.Load<Texture2D>("CollisionBoundary"));

                        
            ////player.AgentType = agent_Type.ROCK;
            ////enemy.AgentType = agent_Type.PAPER;
            ////test.AgentType = agent_Type.SCISSOR;

            //player.Collision_Radius = 100.0f;
            //enemy.Collision_Radius = 100.0f;

            //player.Speed_Normal = 1.5f;
            //enemy.Speed_Normal = 1.5f;

            ////player.Position = Helper.Position_Random(xPosSeed, yPosSeed, 50, 750, 50, 550);
            ////enemy.Position = Helper.Position_Random(xPosSeed, yPosSeed, 50, 750, 50, 550);
            ////test.Position = Helper.Position_Random(50, 750, 50, 550);

            ////player.Size = enemy.Size = new Vector2(16.0f);

            //player.AngleInRadians = Helper.Degree2Radian(0.0f);
            //enemy.AngleInRadians = Helper.Degree2Radian(0.0f);
            #endregion


            crtl = Controller.Instance();

            for (int i = 0; i < ctr; ++i)
            {
                crtl.AddPaper(new Paper(Content.Load<Texture2D>("Paper_16x16")));
                crtl.AddRock(new Rock( Content.Load<Texture2D>("Rock_16x16") ) );
                crtl.AddScissor(new Scissor(Content.Load<Texture2D>("Scissor_16x16")));
            }

            base.Initialize();
        }


        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            font = Content.Load<SpriteFont>("DebugFont");
        }

       
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }


        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            //Exit when pressed 'Escape'
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            #region PREV CODE_BASE
            //
            ////if ((Keyboard.GetState().IsKeyDown(Keys.Right)))
            ////{
            ////    player.AngleInRadians += Helper.Degree2Radian(1.0f);
            ////    enemy.AngleInRadians += Helper.Degree2Radian(1.0f);

            ////}
            ////else if ((Keyboard.GetState().IsKeyDown(Keys.Left)))
            ////{
            ////    enemy.AngleInRadians += Helper.Degree2Radian(-1.0f);
            ////    player.AngleInRadians += Helper.Degree2Radian(-1.0f);
            ////}

            ////if ((Keyboard.GetState().IsKeyDown(Keys.Up)))
            ////{
            ////    player.Position += Helper.Radian2Vector(player.AngleInRadians);
            ////}
            ////if ((Keyboard.GetState().IsKeyDown(Keys.Down)))
            ////{
            ////    player.Position -= Helper.Radian2Vector(player.AngleInRadians);
            ////}

            ////player.Update_Behaviour(enemy, gameTime);
            ////enemy.Update_Behaviour(player, gameTime);
            //test.Update_Behaviour(player gameTime);

            ////if (!player.IsAlive)
            ////{
            ////    player.IsAlive = true;
            ////    player.AngleInRadians = Helper.AngleInRadians_Random();
            ////    player.Position = Helper.Position_Random(50, 750, 50, 550);
            ////}

            ////if (!enemy.IsAlive)
            ////{
            ////    enemy.IsAlive = true;
            ////    enemy.AngleInRadians = Helper.AngleInRadians_Random();
            ////    enemy.Position = Helper.Position_Random(50, 750, 50, 550);
            ////}
            //
            #endregion


            crtl.Update(gameTime);

            base.Update(gameTime);
        }

        
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);
            
            spriteBatch.Begin();

            #region PREV CODE_BASE
            //
            ////player.Draw(spriteBatch, font, new Vector2() );
            ////enemy.Draw(spriteBatch, font, new Vector2 (0.0f, 200.0f) );
            //test.Draw(spriteBatch, font, new Vector2(0.0f, 400.0f));
            #endregion


            crtl.Draw(spriteBatch);

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
